#!/bin/bash

# ----------------------------------------------------------------------
# Filename:   tftp_start.sh
# Version:    1.0
# Date:       2013/05/15
# Author:      huijing.hei
# Email:       huijing.hei@cs2c.com.cn
# Summary:     02系统基本功能-04网络服务-02tftp-01启动服务
# Notes:       depends on tftp_start_s1.sh
# Copyright:    China Standard Software Co., Ltd.
# History：     
#             Version 1.0, 2013/05/15
#             - Start tftp service.
# ----------------------------------------------------------------------
# include lib files
if [ -z "$SFROOT" ]
then
    CMDLIB=./
    SFROOT=./
else
    CMDLIB=${SFROOT}/testcases/Network_Service
fi

. ${SFROOT}/lib/Echo.sh
. ${CMDLIB}/lib/Net.sh
. ${SFROOT}/lib/XmlParse.sh

. ${CMDLIB}/setup.sh

# get RHOST, RUSERNAME, PASSWORD from config.xml
DATA_FILE="${SFROOT}/testcases/Network_Service/config.xml"
[ -e $DATA_FILE ] || { echo "$DATA_FILE not find, test end."; exit 1; }

XmlParse ${DATA_FILE}

GetValue REHOST ReHost
GetValue RUSERNAME UserName
GetValue PASSWORD RootPasswd

export RHOST=${REHOST}
export RUSERNAME=${RUSERNAME}
export PASSWORD=${PASSWORD}

# check tftp package
RE=`${RSH} -n -l root $RHOST "rpm -qa | grep tftp-server"`
echo "${RE}" | grep tftp-server
EchoResult "remote tftp-server installed"

exists tftp expect
EchoResult "check commands"

setup_env || { echo "setup env failed, test end."; exit 1; }


${RCP} tftp_start_s1.sh root@$RHOST:~/
EchoResult "rcp tftp_start_s1.sh to $RHOST"

${RSH} -n -l root $RHOST "sh tftp_start_s1.sh"
EchoResult "exec tftp_start_s1.sh on $RHOST"

RC=`${RSH} -n -l root $RHOST "netstat -ap | grep tftp"`
echo ${RC} | grep tftp
EchoResult "tftp start on $RHOST"

${RSH} -n -l root $RHOST "rm -f tftp_start_s1.sh"
